package com.linjing.trade.controller;

import com.linjing.item.model.ItemBo;
import com.linjing.item.service.ItemService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 仇冬林
 * @date 2022/5/8
 */

@RestController
@RequestMapping("/dubbo")
public class DubboTestController {

    @DubboReference(group = "*")
    private ItemService anyItemService;
    @DubboReference(group = "common")
    private ItemService commonNovItemService;
    @DubboReference(group = "common", version = "1.0")
    private ItemService commonV1ItemService;
    @DubboReference(group = "common", version = "2.0")
    private ItemService commonV2ItemService;
    @DubboReference(group = "simple")
    private ItemService simpleItemService;

    //
    @GetMapping("/any/{id}")
    public String testDubboAny(@PathVariable("id") Long id){
        ItemBo item = new ItemBo();
        item.setId(id);
        item.setItemCode("itemCode:" + id);
        item.setItemName("itemName:" + id);
        return anyItemService.addItem(item);
    }

    @GetMapping("/simple/{id}")
    public String testDubboSimple(@PathVariable("id") Long id){
        ItemBo item = new ItemBo();
        item.setId(id);
        item.setItemCode("itemCode:" + id);
        item.setItemName("itemName:" + id);
        return simpleItemService.addItem(item);
    }

    @GetMapping("/common/{id}")
    public String testDubboCommon(@PathVariable("id") Long id){
        ItemBo item = new ItemBo();
        item.setId(id);
        item.setItemCode("itemCode:" + id);
        item.setItemName("itemName:" + id);
        return commonNovItemService.addItem(item);
    }

    @GetMapping("/common/v1/{id}")
    public String testDubboCommonV1(@PathVariable("id") Long id){
        ItemBo item = new ItemBo();
        item.setId(id);
        item.setItemCode("itemCode:" + id);
        item.setItemName("itemName:" + id);
        return commonV1ItemService.addItem(item);
    }

    @GetMapping("/common/v2/{id}")
    public String testDubboCommonV2(@PathVariable("id") Long id){
        ItemBo item = new ItemBo();
        item.setId(id);
        item.setItemCode("itemCode:" + id);
        item.setItemName("itemName:" + id);
        return commonV2ItemService.addItem(item);
    }

}
